package com.AJava1710D.设计模式.代理模式.dong.cglib;

import com.alibaba.fastjson.JSON;
import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * 作者: LCG
 * 日期: 2020/6/28 10:58
 * 描述:
 */
public class My00MethodInterceptor<T> implements MethodInterceptor {

    private Object object;

    public My00MethodInterceptor(Object object) {
        this.object = object;
    }

    private Enhancer enhancer=new Enhancer();

    public T getObject(Class<?> classe){

        enhancer.setSuperclass(classe);
        enhancer.setCallback(this);

        return (T)enhancer.create();
    }

    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {

        System.out.println("====之前====");
        method.invoke(object,objects);
        System.out.println("====之后====");
        return null;
    }
}
